jQuery(function(){
    $("#div-form-registro, #div-form-edit").dialog({
        autoOpen: false, 
        modal:true, 
        show: 'bind', 
        hide: 'clip', 
        height: 455, 
        width: 575
    });
    
    $("#div-form-edit").dialog({
        open: function(evnt, ui){
            recargaFormEdit(ui, evnt);
        }
    });
    
    
    $("#btn-openRegistro").button({
        icons: {primary:'ui-icon-plus'}
    }).click(function(){
        $("#div-form-registro").dialog("open");
    });
    $("#form-control-registros\\:btn-updateList").button({
        text: false, 
        icons:{
            primary: 'ui-icon-arrowrefresh-1-s'
        }
    });
});
                                
function recargaFormEdit(elm, evnt){
    mojarra.ab(elm, evnt, 'click', 0, 'form-edit');
    return false;
}
function recargaLista(elm, evnt){
    if(evnt.status == 'success'){
        mojarra.ab(elm, evnt, 'click', 0, 'action-personas:tabPersonas');
    }
    return false;
}

// Eventos para la edicion de institucion
function openEdit(evnt){
    if(evnt.status == 'success'){
        $("#div-form-edit").dialog("open");
    }
    return false;
}
function eventoEdicion(elm, evnt){
    var baseEdita = new SATK.Forms.Msg.init("#msg-edita", "Se actualizo exitosamente el registro.");
    var resp = SATK.Forms.ajaxResponce(evnt, baseEdita);    
    if(resp == 'true'){
        recargaLista(elm, evnt);
        setTimeout(function(){
            $("#div-form-edit").dialog("close");
            $(baseEdita.elmBox).html("");
        }, 3000);
    }
}
function eventCancelEdit(){
    $("#msg-edita").html("");
    $("#div-form-edit").dialog("close");
}

// Eventos para el registro de una institución
function eventRegistro(elm, evnt){
    var baseRegistro = new SATK.Forms.Msg.init("#msg-registro", "Se registro exitosamente a la persona.");
    var resp = SATK.Forms.ajaxResponce(evnt, baseRegistro);
    if(resp == 'true'){
        recargaLista(elm, evnt);
    }
}